package roborally.script.composedCondition;

import exception.IllegalScriptSyntaxException;
import roborally.model.Robot;
import roborally.script.ComposedCondition;
import roborally.script.Condition;
import be.kuleuven.cs.som.annotate.*;
import be.kuleuven.cs.som.taglet.*;

/**
 * @author Joren VERSPEURT
 * @author Mathieu REYMOND
 * @version 3.0
 * 
 * The class representing an Or statement in the RoboRally script language.
 */
public class Or extends ComposedCondition {

	/**
	 * Creates a new Or-condition with a given Robot. This Condition is composed by at least two sub-conditions (that are given as parameters).
	 * @param robot The Robot this Condition will apply to.
	 * @param conditions The sub-conditions of this Or statement.
	 * @throws IllegalScriptSyntaxException This Condition must be composed by at least two sub-conditions
	 */
	public Or(Robot robot, Condition... conditions)
			throws IllegalScriptSyntaxException {
		super(robot, conditions);
		if(conditions.length < 2) throw new IllegalScriptSyntaxException("At least 2 conditions required for an or statement.");
	}

	/**
	 * This Condition is true if at least one of its sub-conditions is true.
	 */
	@Override
	public boolean isTrue() {
		boolean result = false;
		for(Condition condition : getConditions()){
			result |= condition.isTrue();
		}
		return result;
	}
	
	/**
	 * The script word for this condition.
	 */
	@Override
	public String toString() {
		return "or";
	}

}
